package com.tutu.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.tutu.IMApplication;

/**
 * @author 图图 2020/10/11
 *
 */
public class SpUtils {
    // 新邀请标记
    public static final String IS_NEW_INVITE = "is_new_invite";
    private static SharedPreferences mSp;
    private static SpUtils spUtils = new SpUtils();

    private  SpUtils(){}

    public static SpUtils getInstance(){
        if(mSp == null) {
            mSp = IMApplication.getGlobalApplication().getSharedPreferences("im", Context.MODE_PRIVATE);
        }

        return spUtils;
    }

    /**
     * 保存
     * @param key
     * @param value
     */
    public void save(String key,Object value){
       if (value instanceof String){
           mSp.edit().putString(key,value.toString()).commit();
           return;
       }
       if (value instanceof Boolean){
            mSp.edit().putBoolean(key, (Boolean) value).commit();
            return;
       }
       if (value instanceof Integer){
            mSp.edit().putInt(key, (Integer) value).commit();
            return;
       }
    }

    /**
     * 获取数据的方法
     * @param key
     * @param defValue
     * @return
     */
    public String getString(String key,String defValue){
        return mSp.getString(key,defValue);
    }

    /**
     * 获取Boolean类型的数据
     * @param key
     * @param defValue
     * @return
     */
    public  boolean getBoolean(String key,boolean defValue){
        return mSp.getBoolean(key,defValue);
    }

    /**
     * 获取int类型的数据
     * @param key
     * @param defValue
     * @return
     */
    public int getInt(String key,int defValue){
        return mSp.getInt(key,defValue);
    }



}
